package com.example.downloaddemo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 下载线程类
 * 
 */
public class DownloadThread extends Thread {

	private String downloadUrl = null;

	public DownloadThread() {

	}

	public DownloadThread(String url) {
		this.downloadUrl = url;
	}

	@Override
	public void run() {
		InputStream is = null;
		StringBuffer sb = null;
		try {
			URL url = new URL(downloadUrl);
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setConnectTimeout(5000);
			conn.setDoInput(true);
			conn.setRequestMethod("GET");
			if (conn.getResponseCode() == 200) {
				// 开始下载
				is = conn.getInputStream();
				BufferedReader br = new BufferedReader(
						new InputStreamReader(is));
				String line = "";
				sb = new StringBuffer();
				while ((line = br.readLine()) != null) {
					sb.append(line);
				}
				
//				byte[] b = sb.toString().getBytes();

			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	/**
	 * 创建
	 */
}
